// Social Network Simulator
// snsim.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <cstdlib>
#include <cstring>

#include "des.h"
#include "newtypes.h"

using namespace std;

// Global variables
// The input parameter object
Param param;
base_generator_type generator(42u);

void parse_inputs(Param &p, int argc, char *argv[])
{
    if ((argc == 2) && (!strncmp(argv[1], "-h", 2))) {
        cerr << "Usage: " << argv[0]
            << " -n_actors <N> -cost <C> "
            << " -delta <d> -random_seed <random_seed> -expt <experiment> "
            << " -density <density> -n_repeat <repeat> "
            << "-n_iterations <nstop> -n_idle_terminate <n_idle> "
            << endl;
        exit(0);
    }
    for (int i = 1; i < argc-1; i += 2) {
        if (!strcmp(argv[i], "-n_actors")) {
            p.N = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-cost")) {
            p.c = atof(argv[i+1]);
        } else if (!strcmp(argv[i], "-delta")) {
            p.delta = atof(argv[i+1]);
        } else if (!strcmp(argv[i], "-density")) {
            p.density = atof(argv[i+1]);
        } else if (!strcmp(argv[i], "-expt")) {
            p.expt = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-n_repeat")) {
            p.n_repeat = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-n_iterations")) {
            p.n_iterations = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-n_idle_terminate")) {
            p.n_idle_terminate = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-random_seed")) {
            p.random_seed = atoi(argv[i+1]);
        } else if (!strcmp(argv[i], "-dump")) {
            p.dump = atoi(argv[i+1]);
        } else {
            cerr << "use -help to get help " << endl;
            exit(0);
        }
    }
}

// For information about input parametes, refer pp 228 (section 4.2)
// N.P. Hummon
int main(int argc, char* argv[])
{
    parse_inputs(param, argc, argv);

    // seeding with current time !
    generator.seed(static_cast<unsigned int>(param.random_seed));

    DES simulator(param);

    simulator.execute("socialNetwork", param.dump);

    // simulator.test();

    return 0;
}
